var fs = require('fs');

function FileObject(fileName) {
	this.filename = fileName;
	console.log(this.filename);
	this.file_exits = function(cb) {
		console.log("about to open:" + this.filename);
		fs.open(this.filename, 'r', (err, handle) => {
			if(err) {
				console.log("failed to open file"+ err);
				cb(err);
				return;
			}
			fs.close(handle, () => {

			});
			cb(null, true);
		})
	}
}

let fo1 = new FileObject('info.txt');
let fo2 = new FileObject('invalid.txt');

fo1.file_exits((err, result)=>{
	if(err) {
		console.log("file1 does not exit");
		return
	}
	console.log("file exits!");
});
fo2.file_exits((err, result)=>{
    if(err) {
        console.log("file2 does not exit");
        return
    }
    console.log("file exits!");
});